home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 4
/
Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso
/
Development
/
General
/
Kamprath's CDEF Pack ƒ
/
CDEF Sampler Program ƒ
/
samplerMenus.c
< prev
next >
Wrap
Text File
|
1993-10-16
|
3KB
|
149 lines
/*****
* bullMenus.c
*
* Routines for Bullseye demo menus.
*
*****/
#include "samplerMenus.h"
extern WindowPtr samplerWindow;
MenuHandle appleMenu, fileMenu, editMenu;
enum {
appleID = 1,
fileID,
editID
};
enum {
openItem = 1,
closeItem,
quitItem = 4
};
/****
* SetUpMenus()
*
* Set up the menus. Normally, we’d use a resource file, but
* for this example we’ll supply “hardwired” strings.
*
****/
void SetUpMenus(void)
{
InsertMenu(appleMenu = NewMenu(appleID, "\p\024"), 0);
InsertMenu(fileMenu = NewMenu(fileID, "\pFile"), 0);
InsertMenu(editMenu = NewMenu(editID, "\pEdit"), 0);
DrawMenuBar();
AddResMenu(appleMenu, 'DRVR');
AppendMenu(fileMenu, "\pOpen/O;Close/W;(-;Quit/Q");
AppendMenu(editMenu, "\pUndo/Z;(-;Cut/X;Copy/C;Paste/V;Clear");
}
/* end SetUpMenus */
/****
* AdjustMenus()
*
* Enable or disable the items in the Edit menu if a DA window
* comes up or goes away. Our application doesn't do anything with
* the Edit menu.
*
****/
int enable (MenuHandle menu, short item, short ok);
void AdjustMenus(void)
{
register WindowPeek wp = (WindowPeek) FrontWindow();
short kind = wp ? wp->windowKind : 0;
Boolean DA = kind < 0;
enable(editMenu, 1, DA);
enable(editMenu, 3, DA);
enable(editMenu, 4, DA);
enable(editMenu, 5, DA);
enable(editMenu, 6, DA);
enable(fileMenu, openItem, !((WindowPeek) samplerWindow)->visible);
enable(fileMenu, closeItem, DA || ((WindowPeek) samplerWindow)->visible);
}
static
enable(MenuHandle menu, short item, short ok)
{
if (ok)
EnableItem(menu, item);
else
DisableItem(menu, item);
}
/*****
* HandleMenu(mSelect)
*
* Handle the menu selection. mSelect is what MenuSelect() and
* MenuKey() return: the high word is the menu ID, the low word
* is the menu item
*
*****/
void HandleMenu (long mSelect)
{
int menuID = HiWord(mSelect);
int menuItem = LoWord(mSelect);
Str255 name;
GrafPtr savePort;
WindowPeek frontWindow;
switch (menuID)
{
case appleID:
GetPort(&savePort);
GetItem(appleMenu, menuItem, name);
OpenDeskAcc(name);
SetPort(savePort);
break;
case fileID:
switch (menuItem)
{
case openItem:
ShowWindow(samplerWindow);
SelectWindow(samplerWindow);
break;
case closeItem:
if ((frontWindow = (WindowPeek) FrontWindow()) == 0L)
break;
if (frontWindow->windowKind < 0)
CloseDeskAcc(frontWindow->windowKind);
else if (frontWindow = (WindowPeek) samplerWindow)
HideWindow(samplerWindow);
break;
case quitItem:
ExitToShell();
break;
}
break;
case editID:
if (!SystemEdit(menuItem-1))
SysBeep(5);
break;
}
}
/* end HandleMenu */